package com.hu.zhcc.shiro.controller;

import com.github.pagehelper.PageInfo;
import com.hu.zhcc.shiro.entity.bo.Category;
import com.hu.zhcc.shiro.entity.vo.CategoryVO;
import com.hu.zhcc.shiro.service.CategoryService;
import com.hu.zhcc.shiro.service.TherapyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 人群分类
 */

@RestController
@CrossOrigin
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService CategoryService;
    @Autowired
    private TherapyService therapyService;

    @GetMapping("")
    public PageInfo<Category> homeCategory(CategoryVO CategoryVO){
        PageInfo<Category> CategoryPageInfo = CategoryService.pageQuery(CategoryVO);
        return CategoryPageInfo;
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<?> removeCategory(@PathVariable("id") Short id) {
        return CategoryService.removeCategory(id) ? ResponseEntity.noContent().build() :
                ResponseEntity.notFound().build();
    }

    @PutMapping("/{id}")
    public ResponseEntity<Integer> updateRouter(@PathVariable("id") int id, @RequestBody Category Category) {
        return CategoryService.updateCategory(Category) ? ResponseEntity.noContent().build() :
                ResponseEntity.notFound().build();
    }

}
